<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form>
            <p:panel >
                <f:facet name="header">
                    <p:outputLabel value="Select Request For Department : #{sessionController.department.name}"/>      
                    <h:panelGrid columns="5" >
                        <h:outputLabel value="From Date"/>
                        <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                        </p:calendar>
                        <h:outputLabel value="To Date"/>
                        <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                        </p:calendar>
                        <p:commandButton id="btnSearch1" ajax="false" value="Search All" 
                                         action="#{searchController.createInwardBHTForIssueTableAll}" />
                        <p:commandButton id="btnSearch2" ajax="false" value="Search Not Issued" 
                                         action="#{searchController.createInwardBHTForNotIssueTable}" />
                        <p:commandButton id="btnSearch3" ajax="false" value="Search Isssued Only" 
                                         action="#{searchController.createInwardBHTForIssueOnlyTable}" />
                        <p:spacer height="30"/><h:outputLabel/><h:outputLabel/>

                        <h:outputLabel value="Request No"/>   
                        <h:outputLabel value="BHT No"/> 
                        <h:outputLabel/><h:outputLabel/><h:outputLabel/>
                        <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />   
                        <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.bhtNo}" />                                                
                        <h:outputLabel/><h:outputLabel/>
                    </h:panelGrid>
                </f:facet>



                <p:dataTable value="#{searchController.bills}" var="p" >
                    <p:column headerText="Request No">                      
                        <h:outputLabel value="#{p.deptId}"/>                         
                    </p:column>
                    <p:column headerText="Department Form request">                      
                        <h:outputLabel value="#{p.department.name}"/>                          
                    </p:column> 
                    <p:column headerText="BHT No">                      
                        <h:outputLabel value="#{p.patientEncounter.bhtNo}"/>                          
                    </p:column> 
                    <p:column headerText="Requested at"  >
                        <h:outputLabel value="#{p.createdAt}" >
                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                        </h:outputLabel>
                        <br/>
                        <h:panelGroup rendered="#{p.cancelled}" >
                            <h:outputLabel style="color: red;" value="Cancelled at " />
                            <h:outputLabel style="color: red;" rendered="#{p.cancelled}" 
                                           value="#{p.cancelledBill.createdAt}" >
                                <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                            </h:outputLabel>
                        </h:panelGroup>

                    </p:column>                 
                    <p:column headerText="Requested by" >                      
                        <h:outputLabel value="#{p.creater.webUserPerson.name}" >                                      
                        </h:outputLabel>                          
                        <br/>
                        <h:panelGroup rendered="#{p.cancelled}" >
                            <h:outputLabel style="color: red;" value="Cancelled By " />
                            <h:outputLabel style="color: red;" rendered="#{p.cancelled}" value="#{p.cancelledBill.creater.webUserPerson.name}" >                                       
                            </h:outputLabel>
                        </h:panelGroup>
                    </p:column>  
                    <p:column>
                        <p:commandButton ajax="false" value="View Request" action="ward_pharmacy_reprint_bht_issue_request">
                            <f:setPropertyActionListener value="#{p}" target="#{pharmacyBillSearch.bill}"/>
                        </p:commandButton>
                    </p:column>
                    <p:column >
                        <p:commandButton ajax="false" value="Issue" action="ward_pharmacy_bht_issue" actionListener="#{pharmacySaleBhtController.generateBillComponent(p)}"
                                         disabled="#{p.cancelled eq true}">
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="Issued">                   
                        <p:dataTable var="b" value="#{p.listOfBill}">                           
                            <p:column  >                                                               
                                <h:outputLabel  value="#{b.deptId}"/>                                   
                            </p:column>
                            <p:column >
                                <h:outputLabel value="#{b.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{b.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{b.cancelled}"
                                                   value="#{b.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>                               
                            </p:column>                             
                            <p:column >
                                <h:outputLabel value="#{b.creater.webUserPerson.name}"/>     
                                <br/>
                                <h:panelGroup rendered="#{b.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled By " />
                                    <h:outputLabel style="color: red;" rendered="#{b.cancelled}" value="#{b.cancelledBill.creater.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column> 
                            <p:column >                              
                                <h:outputLabel value="#{b.toStaff.person.nameWithTitle}"/>                                   
                            </p:column> 
                            <p:column>
                                <p:commandButton ajax="false" value="View Issue Bill" action="/ward/ward_pharmacy_reprint_bht_issue_bill_reprint" >
                                    <f:setPropertyActionListener target="#{pharmacyBillSearch.bill}" value="#{b}"/>
                                </p:commandButton>
                            </p:column>

                        </p:dataTable>
                    </p:column>
                </p:dataTable>
            </p:panel>
        </h:form>
    </ui:define>  

</ui:composition>
